//
//  ViewController.m
//  LiWuShuo
//
//  Created by 苗钧豪 on 16/8/2.
//  Copyright © 2016年 苗钧豪. All rights reserved.
//

#import "ViewController.h"
#import "myView.h"
#import "CollectionReusableView.h"
#import "mainCollectionViewCell.h"

@interface ViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:layout];
    layout.itemSize = CGSizeMake((self.view.bounds.size.width - 50) / 2, 100);
    layout.headerReferenceSize = CGSizeMake(0, 50);
//    layout.sectionInset = UIEdgeInsetsMake(500, 20, 20, 20);
    collectionView.backgroundColor = [UIColor whiteColor];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    collectionView.contentInset = UIEdgeInsetsMake(500, 20, 20, 20);
    [self.view addSubview:collectionView];
    [collectionView registerClass:[mainCollectionViewCell class] forCellWithReuseIdentifier:@"1"];
    myView *myview = [[myView alloc]initWithFrame:CGRectMake(0, - 495, self.view.bounds.size.width, 400)];
    [collectionView addSubview:myview];
    [collectionView registerClass:[CollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"123"];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 10;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    mainCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"1" forIndexPath:indexPath];
    cell.contentView.backgroundColor = [UIColor redColor];
    cell.imageview.image = [UIImage imageNamed:[NSString stringWithFormat:@"m%ld",indexPath.row + 1]];
    return cell;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    CollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"123" forIndexPath:indexPath];
    return view;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
